package com.lihan.GetSeatInLib.Jobs;

import java.util.Set;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import com.google.common.collect.Tables;
import com.lihan.GetSeatInLib.Domain.LibTable;
import com.lihan.GetSeatInLib.Domain.SeatModel;
import com.lihan.GetSeatInLib.Domain.Enums.SeatStaus;
import com.lihan.GetSeatInLib.Domain.Enums.TableStatus;
import com.lihan.GetSeatInLib.Service.LibTableService;
import com.lihan.GetSeatInLib.Service.SeatService;

/**
 * 
 * @ClassName: Clean_LockTableSeat_ToLocked
 * @Description: 将被锁定的座子的还在USED状态的全部改变为LOCKED
 * @author ASUS
 * @date 2022年3月13日
 *
 */
public class Clean_LockTableSeat_ToLocked  extends QuartzJobBean{
	
	
	//将业务对象传入（当然不是Spring导入）
	private LibTableService tableService;
	
	//用于锁定座位
	private SeatService seatService;

	public LibTableService getTableService() {
		return tableService;
	}

	public void setTableService(LibTableService tableService) {
		this.tableService = tableService;
	}
	
	
	@Override
	protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
		
		Set<LibTable> seatSet = tableService.getAllLibTale();
		//先遍历所有的桌子
		seatSet.forEach(item->{
			
			Set<SeatModel> seatlist = item.getSeatlist();
			
			if(item.getStatus()==TableStatus.LOCKED) {
				//再遍历被锁定的桌子下的桌位
				seatlist.forEach((innerItem)->{
					if(innerItem.getStatus()==SeatStaus.USED) {
						//修改状态
						innerItem.setStatus(SeatStaus.LOCKED);
						seatService.UpdateSeat(innerItem);
					}
				});
			}
			
			
		});
		System.out.println("定时任务执行完毕");
	}
	

}
